<!DOCTYPE html>
<html>
<head>
    <include file="Public:header" />
    <!-- jqgrid-->
    <link href="__ACSS__/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox ">
                    <div class="ibox-content">
                    	<div class="ibox-search-box">
                    		<div class="row">
	                    		<div class="infont col-md-2">
		                    		<input type="text" name="username" class="form-control" placeholder="用户名">
								</div>
								<div class="infont col-md-2">
		                    		<input type="text" name="tel" class="form-control" placeholder="电话">
								</div>
	                    		<div class="infont col-md-2">
	                    			<button class="btn btn-success btn-block btn-ibox-search" type="button">搜索</button>
	                    		</div>
                    		</div>
                    	</div>
                    	<p>
                    		<button type="button" id="editPwd" class="btn btn-white btn-sm btn-outline"><i class="fa fa-edit"></i>&nbsp;重置密码</button>
                    		<button type="button" id="editTel" class="btn btn-white btn-sm btn-outline"><i class="fa fa-edit"></i>&nbsp;更换手机号码</button>
                   			<button type="button" id="detail" class="btn btn-white btn-sm btn-outline"><i class="fa fa-table"></i>&nbsp;账户明细</button>
                   			<button type="button" id="address" class="btn btn-white btn-sm btn-outline"><i class="fa fa-table"></i>&nbsp;查看地址</button>
                    	</p>
                        <div class="jqGrid_wrapper">
                            <table id="table_list"></table>
                            <div id="pager_list"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<!-- 全局js -->
<include file="Public:foot" />
<!-- jqGrid -->
<script src="__AJSPLUGINS__/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="__AJSPLUGINS__/jqgrid/jquery.jqGrid.min.js?0820"></script>
<!-- Page-Level Scripts -->
<script>
$(document).ready(function () {
	//初始化
    $.jgrid.defaults.styleUI = 'Bootstrap';
    $("#table_list").jqGrid({
    	url : '__URL__/getAllData',
        datatype: "json",
        height: 520,
        autowidth: true,
        shrinkToFit: true,
        rowNum: 15,
        rowList: [10, 15, 30, 50],
        colNames : [ 'id', '用户名', '电话', '账户余额（共：<{$balance}>）'],
        colModel : [ {name : 'id',index : 'id'},
                     {name : 'username',index : 'username'},
                     {name : 'tel',index : 'tel'},
                     {name : 'balance',index : 'balance'}
                   ],
        pager: "#pager_list",
        viewrecords: true,
        hidegrid: false,
        sortname: "id",
        sortorder: "desc",
        ondblClickRow: function(rowid) {
        	if(rowid != null) {
        		layerDialog("详细",'__URL__/detailView?id='+rowid,"90%","90%",true);
        	}else {
        		layer.msg("您没有选取数据！");
        	}
        }
    });
    
    //搜索
    $(".btn-ibox-search").click(function() {
    	result = getSearchParamByInput();
    	$("#table_list").jqGrid('setGridParam', { 
    		page: 1,
    		url : '__URL__/getAllData' + result
    	}).trigger("reloadGrid");
    })
    //监控回车
    $(".ibox-search-box").find(":input").keydown(function(event) {
		if(event.keyCode == 13){
			$(".btn-ibox-search").trigger("click");
		}
	})
    
    //获取搜索条件（仅限封装简单条件）
    function getSearchParamByInput() {
    	var result = "";
    	$(".ibox-search-box").find(":input").each(function() {
    		if($(this).val() != "") {
    			if(result != "") {
    				result += "&";
    			}else{
    				result += "?";
    			}
    			result += $(this).attr("name") + "=" + $(this).val();
    		}
    	})
    	return result;
    }
    
 	// 设置按钮
    $("#table_list").jqGrid('navGrid', '#pager_list', {
        edit: false,
        add: false,
        del: false,
        search: false
    }, {
        height: 200,
        reloadAfterSubmit: true
    });
    // 添加适配响应
    $(window).bind('resize', function () {
        var width = $('.jqGrid_wrapper').width();
        $('#table_list').setGridWidth(width);
    });
    
});

//账户明细
$("#detail").click(function() {
	var id = $("#table_list").jqGrid('getGridParam','selrow');
	if(id != null) {
		layerDialog("账户明细",'__URL__/detail?id='+id,"90%","90%",true);
	}else {
		layer.msg("您没有选取数据！");
	}
})
//查看地址
$("#address").click(function() {
	var id = $("#table_list").jqGrid('getGridParam','selrow');
	if(id != null) {
		layerDialog("查看地址",'__URL__/address?id='+id,"90%","90%",true);
	}else {
		layer.msg("您没有选取数据！");
	}
})

$("#editPwd").click(function(){
	var id = $("#table_list").jqGrid('getGridParam','selrow');
	if(id != null) {
		resetPwd(id);
	}else {
		layer.msg("您没有选取数据！");
	}
})
//修改手机号码
$("#editTel").click(function() {
	var id = $("#table_list").jqGrid('getGridParam','selrow');
	if(id != null) {
		layerDialog("修改手机号码",'__URL__/modifyTel?id='+id,"90%","40%",true);
	}else {
		layer.msg("您没有选取数据！");
	}
})

//重置密码
function resetPwd(id) {
	layer.confirm('密码将重置为 <font style="color:red;">000000</font></br>确定执行？', function(index){
    	var index = layer.load(2);
    	$.ajax({
			url:"__URL__/resetPwd",
			type:"post",
			data:{'id':id,'field':'password','islock':"670b14728ad9902aecba32e22fa4f6bd"},
			success:function(json){
				var data = eval("("+json+")");
				if(data.status == 1){
					layer.msg(data.info);
					$('#table_list').trigger("reloadGrid");
				}else{
					layer.msg(data.info);
				}
				layer.close(index);
			}
		})
	});
}
</script>
</html>